import Lockr from "../assets/js/Lockr";
import config from "../config";

export default {
   setCacheToken(token){
     if(window.terminal.gdEx){
       Lockr.setLocal("authToken", token)
     }else{
       Lockr.set("authToken", token)
     }
   },

   getCacheToken(){
     if(window.terminal.gdEx){
       return Lockr.getLocal("authToken")
     }else{
       return Lockr.get("authToken")
     }

   },

   delCacheToken(){
     if(window.terminal.gdEx){
       Lockr.delLocal('authToken')
     }else{
       Lockr.del('authToken')
     }
   },

   gotoGdexAuth2(){
     let ebuildUrl = location.origin + '/api/auth/qyWx?channel='+channel+'&url=' + encodeURIComponent(location.href)
     let cfg = config.GDEX_CONFIG
     let eUrl = cfg.apiUrl+'connect/oauth2/authorize?appid='+cfg.appid+'&redirect_uri=' + encodeURIComponent(ebuildUrl) + '&response_type=code&scope=snsapi_userinfo&agentid='+cfg.agentid+'&state=STATE#wechat_redirect';
     window.location.replace(eUrl)
   }
}
